package com.api.shopapi.mapper;

import com.api.shopapi.entity.CashierLoginRecord;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface CashierLoginRecordMapper {

    @Insert("insert into cashier_login_record" +
            "(" +
            "CashierLoginRecordCode," +
            "UserCode," +
            "StartTime," +
            "EndTime," +
            "LoginStatus" +
            ")" +
            " value" +
            "(" +
            "#{cashierLoginRecord.CashierLoginRecordCode}," +
            "#{cashierLoginRecord.UserCode}," +
            "#{cashierLoginRecord.StartTime}," +
            "#{cashierLoginRecord.EndTime}," +
            "#{cashierLoginRecord.LoginStatus}" +
            ")")
    int insert(@Param("cashierLoginRecord") CashierLoginRecord cashierLoginRecord);


    @Delete("delete from cashier_login_record where cashierLoginRecordCode=#{cashierLoginRecordCode}")
    int delete(@Param("cashierLoginRecordCode") String cashierLoginRecordCode);


    @Update("update cashier_login_record set " +
            " StartTime=#{cashierLoginRecord.StartTime}," +
            " EndTime=#{cashierLoginRecord.EndTime}," +
            " LoginStatus=#{cashierLoginRecord.LoginStatus}" +
            " where cashierLoginRecordCode=#{cashierLoginRecord.cashierLoginRecordCode}")
    int update(@Param("cashierLoginRecord") CashierLoginRecord cashierLoginRecord);


    @Select("select * from cashier_login_record where cashierLoginRecordCode=#{cashierLoginRecordCode} limit 1")
    CashierLoginRecord getByCashierLoginRecordCode(@Param("cashierLoginRecordCode") String cashierLoginRecordCode);


    @Select("select * from cashier_login_record where userCode=#{userCode} and loginStatus=#{loginStatus}")
    List<CashierLoginRecord> getListByUserCodeLoginStatus(@Param("userCode") String userCode,
                                                          @Param("loginStatus") int loginStatus);

}
